git.cmd.Git.execute(..): fix with_stdout=False#2126
git.cmd.Git.execute(..): fix with_stdout=False#2126Byron merged 2 commits intogitpython-developers:mainfrom
with_stdout=False#2126Conversation
In the event the end-user called one of the APIs with `with_stdout=False`, i.e., they didn't want to capture stdout, the code would crash with an AttributeError or ValueError when trying to dereference the stdout/stderr streams attached to `Popen(..)` objects. Be more defensive by checking the streams first to make sure they're not `None` before trying to access their corresponding attributes. Add myself to AUTHORS and add corresponding regression tests for the change. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
d3d587c to
a64bde9
Compare
Byron
left a comment
There was a problem hiding this comment.
Thanks a lot. This looks good to me.
If the machine doesn't find anything horrendous, we can merge this.
There was a problem hiding this comment.
Pull request overview
Fixes Git.execute(..., with_stdout=False) crashing when stdout/stderr streams are None, and adds regression coverage to prevent future regressions.
Changes:
- Make
Git.execute()defensive againstNonestdout/stderr streams when stripping newlines, copying output, and closing handles. - Add regression tests for
with_stdout=Falsescenarios (with and withoutoutput_stream). - Add contributor entry to
AUTHORSand improve test cleanup robustness inrmtreetests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
git/cmd.py |
Adds None checks around stdout/stderr usage to avoid crashes when stdout isn’t piped. |
test/test_git.py |
Adds regression tests covering with_stdout=False behavior. |
test/test_util.py |
Adds a pytest finalizer to ensure temp directories are cleaned up on platforms with stricter permissions. |
AUTHORS |
Adds a new contributor entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Byron
left a comment
There was a problem hiding this comment.
Needs auto-review comments to be addressed.
0ae13c9 to
335989f
Compare
|
@Byron : I tried dealing with the type hinting issues, but it turned into a lot of onion peeling... I would prefer to delay this for another PR (my WIP branch can be found here: https://github.com/ngie-eign/GitPython/tree/type-checking-rabbit-hole ). |
Prior to this the test would fail [silently] on my macOS host during the test and then pytest would complain loudly about it being an issue post-session (regardless of whether or not the test was being run). Squash the unwritable directory to mute noise complaints from pytest. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
335989f to
6fc4742
Compare
Byron
left a comment
There was a problem hiding this comment.
Alright, let's do this!
Getting python to be sane at runtime is a bit like fighting windmills. And since CI isn't failing, I suppose we are fine enough until someone raises an issue.
In any case, an overhaul shouldn't be too bad if it leads to actual improvements, but there is also a danger as GitPython is 'stable' with all its faults, which makes it something to rely on. Or in other words: The tests probably don't cover all uses out there and an overhaul can be dangerous.
Maybe before spending too much time on this, you also have a good use case that shows why this is better and why this library really should. Change.
In the event the end-user called one of the APIs with
with_stdout=False, i.e., they didn't want to capture stdout, the code would crash with an AttributeError or ValueError when trying to dereference the stdout/stderr streams attached toPopen(..)objects.Be more defensive by checking the streams first to make sure they're not
Nonebefore trying to access their corresponding attributes.Add myself to AUTHORS and add corresponding regression tests for the change.